package pe.com.pamer.siscal.seguridad.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import pe.com.pamer.siscal.bean.Usuario;
import pe.com.pamer.siscal.seguridad.service.LoginService;

@Controller
public class LoginController {

    private static final Logger LOGGER = LoggerFactory.getLogger(LoginController.class);

    @Autowired
    private  LoginService  loginService;


   @RequestMapping(value = "/loginUsuario" , method = RequestMethod.POST)
	public  String  login(Usuario usuario){

        String pagina = "";
       Usuario usuarioLogin = loginService.login(usuario.getLoginUsuario() ,  usuario.getClave());
        if (usuarioLogin != null) {
            pagina = "principal-tiles";
        }else{
            LOGGER.error("El usuario y/o clave son incorrectos");
            pagina = "login";
        }

        return pagina;
	}

@RequestMapping( value = "/login" , method = RequestMethod.GET)
public  String login(){

	return "login";
}

}
